/**
 * JAVACC DEMO 1.0
 * @copy right iussoft company All rights reserved.
 * @Package com.apache.uct.service.plugins  
 */
package com.apache.dict.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.dict.entity.DataCate;
import com.apache.dict.manager.DataCateManager;
import com.apache.dict.manager.DataItemManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DictInfoPluginImpl implements PluginConnector {

	private Logger log = LoggerFactory.getLogger(DictInfoPluginImpl.class);

	private DataItemManager dataItemManager;

	private DataCateManager dataCateManager;

	public Object execute(ParamsVo vo) throws Exception {
		ResultEntity result = new ResultEntity();
		try {
			result.setResult("T");
			String doCode = String.valueOf(vo.getParams("doCode"));
			String cateId = String.valueOf(vo.getParams("cateId"));
			String itemId = String.valueOf(vo.getParams("itemId"));

			if ("dictCateInfo".equals(doCode) && Validator.isNotNull(cateId)) {
				dictCateInfo(result, vo);
			} else {
				result.setMessage("没有可用方法被执行！");
			}
		} catch (Exception e) {
			result.setResult("false");
			log.error("执行机构查询失败 ", e);
			result.setMessage("机构查询失败！");
		}
		return result;
	}

	private void dictCateInfo(ResultEntity result, ParamsVo vo) {
		String cateId = getParamStr(vo, "cateId");
		if (Validator.isNotNull(cateId)) {
			ParamsVo<DataCate> dataCateVo = new ParamsVo<DataCate>();
			dataCateVo.setInfoId(cateId);
			dataCateVo.setMethodKey("ById");
			Object obj = dataCateManager.getInfoById(dataCateVo);
			result.setEntity(obj);
			result.setMessage("查询成功");
		}
	}

	private String getParamStr(ParamsVo vo, String attrName) {
		return Validator.getDefaultStr(String.valueOf(vo.getParams(attrName)), "");
	}

	public void setDataItemManager(DataItemManager dataItemManager) {
		this.dataItemManager = dataItemManager;
	}

	public void setDataCateManager(DataCateManager dataCateManager) {
		this.dataCateManager = dataCateManager;
	}

}
